home *** CD-ROM | disk | FTP | other *** search
/ Collection of Internet / Collection of Internet.iso / msdos / lynx / source / www / library / implemen / htaautil.h < prev    next >
Encoding:
C/C++ Source or Header  |  1994-10-25  |  12.0 KB  |  359 lines

  1. /*                                            Utilities for the Authorization parts of libwww
  2.              COMMON PARTS OF AUTHORIZATION MODULE TO BOTH SERVER AND BROWSER
  3.                                              
  4.    This module is the interface to the common parts of Access Authorization (AA) package
  5.    for both server and browser. Important to know about memory allocation:
  6.    
  7.    Routines in this module use dynamic allocation, but free automatically all the memory
  8.    reserved by them.
  9.    
  10.    Therefore the caller never has to (and never should) free() any object returned by
  11.    these functions.
  12.    
  13.    Therefore also all the strings returned by this package are only valid until the next
  14.    call to the same function is made. This approach is selected, because of the nature of
  15.    access authorization: no string returned by the package needs to be valid longer than
  16.    until the next call.
  17.    
  18.    This also makes it easy to plug the AA package in: you don't have to ponder whether to
  19.    free() something here or is it done somewhere else (because it is always done somewhere
  20.    else).
  21.    
  22.    The strings that the package needs to store are copied so the original strings given as
  23.    parameters to AA functions may be freed or modified with no side effects.
  24.    
  25.    Also note: The AA package does not free() anything else than what it has itself
  26.    allocated.
  27.    
  28.  */
  29.  
  30. #ifndef HTAAUTIL_H
  31. #define HTAAUTIL_H
  32.  
  33. #include "HTUtils.h"            /* BOOL, PARAMS, ARGS */
  34. #include "HTList.h"
  35. #include "tcp.h"
  36.  
  37. #ifdef SHORT_NAMES
  38. #define HTAASenu        HTAAScheme_enum
  39. #define HTAASnam        HTAAScheme_name
  40. #define HTAAMenu        HTAAMethod_enum
  41. #define HTAAMnam        HTAAMethod_name
  42. #define HTAAMinL        HTAAMethod_inList
  43. #define HTAAteMa        HTAA_templateMatch
  44. #define HTAAmaPT        HTAA_makeProtectionTemplate
  45. #define HTAApALi        HTAA_parseArgList
  46. #define HTAAsuRe        HTAA_setupReader
  47. #define HTAAgUfL        HTAA_getUnfoldedLine
  48. #endif /*SHORT_NAMES*/
  49.  
  50.  
  51. /*
  52.  
  53. Default filenames
  54.  
  55.  */
  56. #ifndef PASSWD_FILE
  57. #define PASSWD_FILE     "/home2/luotonen/passwd"
  58. #endif
  59.  
  60. #ifndef GROUP_FILE
  61. #define GROUP_FILE      "/home2/luotonen/group"
  62. #endif
  63.  
  64. #define ACL_FILE_NAME   ".www_acl"
  65.  
  66.  
  67. /*
  68. ** Numeric constants
  69. */
  70. #define MAX_USERNAME_LEN        16      /* @@ Longest allowed username    */
  71. #define MAX_PASSWORD_LEN        3*13    /* @@ Longest allowed password    */
  72.                                         /* (encrypted, so really only 3*8)*/
  73. #define MAX_METHODNAME_LEN      12      /* @@ Longest allowed method name */
  74. #define MAX_FIELDNAME_LEN       16      /* @@ Longest field name in       */
  75.                                         /* protection setup file          */
  76. #define MAX_PATHNAME_LEN        80      /* @@ Longest passwd/group file   */
  77.                                         /* patname to allow               */
  78.  
  79. /*
  80. ** Helpful macros
  81. */
  82. #define FREE(x) if (x) {free(x); x=NULL;}
  83.  
  84. /*
  85.  
  86. Datatype definitions
  87.  
  88.   HTAASCHEME
  89.   
  90.    The enumeration HTAAScheme represents the possible authentication schemes used by the
  91.    WWW Access Authorization.
  92.    
  93.  */
  94.  
  95. typedef enum {
  96.     HTAA_UNKNOWN,
  97.     HTAA_NONE,
  98.     HTAA_BASIC,
  99.     HTAA_PUBKEY,
  100.     HTAA_KERBEROS_V4,
  101.     HTAA_KERBEROS_V5,
  102.     HTAA_MAX_SCHEMES /* THIS MUST ALWAYS BE LAST! Number of schemes */
  103. } HTAAScheme;
  104.  
  105. /*
  106.  
  107.   ENUMERATION TO REPRESENT HTTP METHODS
  108.   
  109.  */
  110.  
  111. typedef enum {
  112.     METHOD_UNKNOWN,
  113.     METHOD_GET,
  114.     METHOD_PUT
  115. } HTAAMethod;
  116.  
  117. /*
  118.  
  119. Authentication Schemes
  120.  
  121.  */
  122.  
  123. /* PUBLIC                                               HTAAScheme_enum()
  124. **              TRANSLATE SCHEME NAME TO A SCHEME ENUMERATION
  125. ** ON ENTRY:
  126. **      name            is a string representing the scheme name.
  127. **
  128. ** ON EXIT:
  129. **      returns         the enumerated constant for that scheme.
  130. */
  131. PUBLIC HTAAScheme HTAAScheme_enum PARAMS((CONST char* name));
  132.  
  133.  
  134. /* PUBLIC                                               HTAAScheme_name()
  135. **                      GET THE NAME OF A GIVEN SCHEME
  136. ** ON ENTRY:
  137. **      scheme          is one of the scheme enum values:
  138. **                      HTAA_NONE, HTAA_BASIC, HTAA_PUBKEY, ...
  139. **
  140. ** ON EXIT:
  141. **      returns         the name of the scheme, i.e.
  142. **                      "none", "basic", "pubkey", ...
  143. */
  144. PUBLIC char *HTAAScheme_name PARAMS((HTAAScheme scheme));
  145.  
  146. /*
  147.  
  148. Methods
  149.  
  150.  */
  151.  
  152. /* PUBLIC                                                   HTAAMethod_enum()
  153. **              TRANSLATE METHOD NAME INTO AN ENUMERATED VALUE
  154. ** ON ENTRY:
  155. **      name            is the method name to translate.
  156. **
  157. ** ON EXIT:
  158. **      returns         HTAAMethod enumerated value corresponding
  159. **                      to the given name.
  160. */
  161. PUBLIC HTAAMethod HTAAMethod_enum PARAMS((CONST char * name));
  162.  
  163.  
  164. /* PUBLIC                                               HTAAMethod_name()
  165. **                      GET THE NAME OF A GIVEN METHOD
  166. ** ON ENTRY:
  167. **      method          is one of the method enum values:
  168. **                      METHOD_GET, METHOD_PUT, ...
  169. **
  170. ** ON EXIT:
  171. **      returns         the name of the scheme, i.e.
  172. **                      "GET", "PUT", ...
  173. */
  174. PUBLIC char *HTAAMethod_name PARAMS((HTAAMethod method));
  175.  
  176.  
  177. /* PUBLIC                                               HTAAMethod_inList()
  178. **              IS A METHOD IN A LIST OF METHOD NAMES
  179. ** ON ENTRY:
  180. **      method          is the method to look for.
  181. **      list            is a list of method names.
  182. **
  183. ** ON EXIT:
  184. **      returns         YES, if method was found.
  185. **                      NO, if not found.
  186. */
  187. PUBLIC BOOL HTAAMethod_inList PARAMS((HTAAMethod        method,
  188.                                      HTList *           list));
  189. /*
  190.  
  191. Match Template Against Filename
  192.  
  193.  */
  194.  
  195. /* PUBLIC                                               HTAA_templateMatch()
  196. **              STRING COMPARISON FUNCTION FOR FILE NAMES
  197. **                 WITH ONE WILDCARD * IN THE TEMPLATE
  198. ** NOTE:
  199. **      This is essentially the same code as in HTRules.c, but it
  200. **      cannot be used because it is embedded in between other code.
  201. **      (In fact, HTRules.c should use this routine, but then this
  202. **       routine would have to be more sophisticated... why is life
  203. **       sometimes so hard...)
  204. **
  205. ** ON ENTRY:
  206. **      template        is a template string to match the file name
  207. **                      agaist, may contain a single wildcard
  208. **                      character * which matches zero or more
  209. **                      arbitrary characters.
  210. **      filename        is the filename (or pathname) to be matched
  211. **                      agaist the template.
  212. **
  213. ** ON EXIT:
  214. **      returns         YES, if filename matches the template.
  215. **                      NO, otherwise.
  216. */
  217. PUBLIC BOOL HTAA_templateMatch PARAMS((CONST char * template,
  218.                                        CONST char * filename));
  219.  
  220.  
  221. /* PUBLIC                                               HTAA_templateCaseMatch()
  222. **              STRING COMPARISON FUNCTION FOR FILE NAMES
  223. **                 WITH ONE WILDCARD * IN THE TEMPLATE (Case Insensitive)
  224. ** NOTE:
  225. **      This is essentially the same code as in HTAA_templateMatch, but
  226. **      it compares case insensitive (for VMS). Reason for this routine
  227. **      is that HTAA_templateMatch gets called from several places, also
  228. **      there where a case sensitive match is needed, so one cannot just
  229. **      change the HTAA_templateMatch routine for VMS.
  230. **
  231. ** ON ENTRY:
  232. **      template        is a template string to match the file name
  233. **                      agaist, may contain a single wildcard
  234. **                      character * which matches zero or more
  235. **                      arbitrary characters.
  236. **      filename        is the filename (or pathname) to be matched
  237. **                      agaist the template.
  238. **
  239. ** ON EXIT:
  240. **      returns         YES, if filename matches the template.
  241. **                      NO, otherwise.
  242. */
  243. PUBLIC BOOL HTAA_templateCaseMatch PARAMS((CONST char * template,
  244.                                          CONST char * filename));
  245.  
  246.  
  247. /* PUBLIC                                       HTAA_makeProtectionTemplate()
  248. **              CREATE A PROTECTION TEMPLATE FOR THE FILES
  249. **              IN THE SAME DIRECTORY AS THE GIVEN FILE
  250. **              (Used by server if there is no fancier way for
  251. **              it to tell the client, and by browser if server
  252. **              didn't send WWW-ProtectionTemplate: field)
  253. ** ON ENTRY:
  254. **      docname is the document pathname (from URL).
  255. **
  256. ** ON EXIT:
  257. **      returns a template matching docname, and other files
  258. **              files in that directory.
  259. **
  260. **              E.g.  /foo/bar/x.html  =>  /foo/bar/ *
  261. **                                                  ^
  262. **                              Space only to prevent it from
  263. **                              being a comment marker here,
  264. **                              there really isn't any space.
  265. */
  266. PUBLIC char *HTAA_makeProtectionTemplate PARAMS((CONST char * docname));
  267. /*
  268.  
  269. MIME Argument List Parser
  270.  
  271.  */
  272.  
  273.  
  274. /* PUBLIC                                               HTAA_parseArgList()
  275. **              PARSE AN ARGUMENT LIST GIVEN IN A HEADER FIELD
  276. ** ON ENTRY:
  277. **      str     is a comma-separated list:
  278. **
  279. **                      item, item, item
  280. **              where
  281. **                      item ::= value
  282. **                             | name=value
  283. **                             | name="value"
  284. **
  285. **              Leading and trailing whitespace is ignored
  286. **              everywhere except inside quotes, so the following
  287. **              examples are equal:
  288. **
  289. **                      name=value,foo=bar
  290. **                       name="value",foo="bar"
  291. **                        name = value ,  foo = bar
  292. **                         name = "value" ,  foo = "bar"
  293. **
  294. ** ON EXIT:
  295. **      returns a list of name-value pairs (actually HTAssocList*).
  296. **              For items with no name, just value, the name is
  297. **              the number of order number of that item. E.g.
  298. **              "1" for the first, etc.
  299. */
  300. PUBLIC HTList *HTAA_parseArgList PARAMS((char * str));
  301.  
  302. /*
  303.  
  304. Header Line Reader
  305.  
  306.  */
  307.  
  308. /* PUBLIC                                               HTAA_setupReader()
  309. **              SET UP HEADER LINE READER, i.e. give
  310. **              the already-read-but-not-yet-processed
  311. **              buffer of text to be read before more
  312. **              is read from the socket.
  313. ** ON ENTRY:
  314. **      start_of_headers is a pointer to a buffer containing
  315. **                      the beginning of the header lines
  316. **                      (rest will be read from a socket).
  317. **      length          is the number of valid characters in
  318. **                      'start_of_headers' buffer.
  319. **      soc             is the socket to use when start_of_headers
  320. **                      buffer is used up.
  321. ** ON EXIT:
  322. **      returns         nothing.
  323. **                      Subsequent calls to HTAA_getUnfoldedLine()
  324. **                      will use this buffer first and then
  325. **                      proceed to read from socket.
  326. */
  327. PUBLIC void HTAA_setupReader PARAMS((char *     start_of_headers,
  328.                                      int        length,
  329.                                      int        soc));
  330.  
  331.  
  332. /* PUBLIC                                               HTAA_getUnfoldedLine()
  333. **              READ AN UNFOLDED HEADER LINE FROM SOCKET
  334. ** ON ENTRY:
  335. **      HTAA_setupReader must absolutely be called before
  336. **      this function to set up internal buffer.
  337. **
  338. ** ON EXIT:
  339. **      returns a newly-allocated character string representing
  340. **              the read line.  The line is unfolded, i.e.
  341. **              lines that begin with whitespace are appended
  342. **              to current line.  E.g.
  343. **
  344. **                      Field-Name: Blaa-Blaa
  345. **                       This-Is-A-Continuation-Line
  346. **                       Here-Is_Another
  347. **
  348. **              is seen by the caller as:
  349. **
  350. **      Field-Name: Blaa-Blaa This-Is-A-Continuation-Line Here-Is_Another
  351. **
  352. */
  353. PUBLIC char *HTAA_getUnfoldedLine NOPARAMS;
  354.  
  355. #endif  /* NOT HTAAUTIL_H */
  356. /*
  357.  
  358.    End of file HTAAUtil.h. */
  359.